import { BasicColumn, FormProps } from '@/components/Table';
import { formatToDate } from '@/utils/dateUtil';
import { FormSchema } from '@/components/Form';
import { getLabelByValue, exerciseFrequencyOption, exerciseTypeOption } from './help/dict';
import { uploadApi, getPhotoUrl } from '@/api/sys/upload';

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      {
        field: `field11`,
        label: `Slot示例`,
        // component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}

/**
 * 配置表格SearchForm字段
 */
export const formConfig: Partial<FormProps> = {
  labelWidth: 100,
  baseColProps: {
    span: 8,
  },
  schemas: [
    {
      field: 'collocation',
      label: '膳食搭配',
      component: 'Input',
    },
    {
      field: 'recommend',
      label: '饮食推荐',
      component: 'Select',
      componentProps: {
        options: exerciseTypeOption,
      },
    },
  ],
};

/**
 * 配置表格表头字段
 */
export const columns: BasicColumn[] = [
  {
    title: 'ID',
    width: 200,
    dataIndex: 'id',
    defaultHidden: true,
  },
  {
    title: '营养师',
    width: 200,
    dataIndex: 'yysUid',
    defaultHidden: true,
  },
  {
    title: '用户',
    width: 200,
    dataIndex: 'uid',
    defaultHidden: true,
  },
  {
    title: '食谱名称',
    width: 200,
    dataIndex: 'title',
  },
  {
    title: '膳食搭配',
    width: 200,
    dataIndex: 'collocation',
  },
  {
    title: '膳食图鉴',
    width: 200,
    dataIndex: 'dataId',
    customRender: ({ record }) => {
      return <img width={100} src={`${getPhotoUrl}${record.dataId}`}></img>;
    },
  },
  {
    title: '饮食推荐',
    width: 200,
    dataIndex: 'recommend',
    customRender: ({ record }) => getLabelByValue(record.recommend, exerciseTypeOption),
  },
  {
    title: '建议内容',
    width: 200,
    dataIndex: 'context',
  },
];

/**
 * form配置
 */
export const schemas: FormSchema[] = [
  {
    field: 'id',
    component: 'Input',
    label: 'ID',
    colProps: {
      span: 20,
    },
    componentProps: {
      disabled: true,
    },
    ifShow: false,
  },
  {
    field: 'yysUid',
    component: 'Input',
    label: '教练',
    colProps: {
      span: 20,
    },
    componentProps: {
      disabled: true,
    },
    ifShow: false,
  },
  {
    field: 'title',
    component: 'Input',
    label: '食谱名称',
    colProps: {
      span: 20,
    },
    rules: [{ required: true, message: '食谱名称不能为空' }],
  },
  {
    field: 'collocation',
    component: 'Input',
    label: '膳食搭配',
    colProps: {
      span: 20,
    },
    rules: [{ required: true, message: '膳食搭配不能为空' }],
  },
  {
    field: 'dataId',
    component: 'ImageUpload',
    label: '膳食图鉴',
    colProps: {
      span: 20,
    },
    // rules: [{ required: true, message: '请上传课程封面' }],
    componentProps: {
      api: uploadApi,
    },
  },
  {
    field: 'recommend',
    component: 'Select',
    label: '饮食推荐',
    colProps: {
      span: 20,
    },
    componentProps: {
      options: exerciseTypeOption,
    },
  },
  {
    field: 'context',
    component: 'InputTextArea',
    label: '备注内容',
    colProps: {
      span: 20,
    },
  },
];

/**
 * table数据
 * @returns
 */
export function initData() {
  return [
    {
      collocation: '香蕉配牛奶',
      dataId:
        'https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '0',
      context: '选择香蕉、牛奶、豆浆、水果、蔬菜、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '蔬菜沙拉',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '1',

      context: '选择蔬菜、沙拉、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '鸡蛋面包',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '1',

      context: '选择鸡蛋、面包、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '豆浆饭',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '1',

      context: '选择豆浆、饭、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '鸡肉饭',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '1',
      context: '选择鸡肉、饭、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '牛肉饭',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '2',
      context: '选择牛肉、饭、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },

    {
      collocation: '鸡蛋面包',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '3',
      context: '选择鸡蛋、面包、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
    {
      collocation: '豆浆饭',
      dataId:
        '	https://ts1.cn.mm.bing.net/th?id=OIP-C.NLY68Af9qQR…HaEl&w=243&h=150&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2',
      recommend: '2',
      context: '选择豆浆、饭、肉类、鱼类等食材，搭配成一道美味的膳食搭配。',
    },
  ];
}
